var base64 = require("../weui/example/images/base64");
//获取应用实例
const app = getApp()

Page({
  data: {
    imageArr: [],
    indicatorDots: false,
    vertical: true,
    autoplay: true,
    interval: 5000,
    duration: 500,
    userId: null,
    notice1Arr: [],
    notice2Arr: [],
    pageNo: 1,
    pageSize: 5,
    wh: 0
  },
  onLoad: function () {
    var that = this;
    if (app.globalData.userId) {
      this.setData({
        userId: app.globalData.userId
      })
    }
    else {
      app.userIdReadyCallback = res => {
        this.setData({
          userId: res.data.userId
        })
      }
    } 
    wx.request({
      url: 'https://www.xinhuo.site/api/ads/list',
      data: {
        adsType: 1
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/json'
      },
      success(res) {
        if (res.data.syscode == 0) {
          that.data.imageArr = res.data.recordList
          that.setData({
            imageArr: that.data.imageArr
          })
        }
      }
    })
    wx.request({
      url: 'https://www.xinhuo.site/api/notice/list',
      data: {
        pageNo: this.data.pageNo,
        pageSize: this.data.pageSize,
        noticeType: 1
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/json'
      },
      success(res) {
        if (res.data.syscode == 0) {
          that.data.notice1Arr = that.data.notice1Arr.concat(res.data.recordList)
          that.setData({
            notice1Arr: that.data.notice1Arr
          })
        }
      }
    })
    wx.request({
      url: 'https://www.xinhuo.site/api/notice/list',
      data: {
        pageNo: this.data.pageNo,
        pageSize: this.data.pageSize,
        noticeType: 2
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/json'
      },
      success(res) {
        if (res.data.syscode == 0) {
          that.data.notice2Arr = that.data.notice2Arr.concat(res.data.recordList)
          that.setData({
            notice2Arr: that.data.notice2Arr
          })
        }
      }
    })
  },
  onPullDownRefresh: function () {
    var that = this;
    wx.request({
      url: 'https://www.xinhuo.site/api/notice/list',
      data: {
        pageNo: this.data.pageNo,
        pageSize: this.data.pageSize,
        noticeType: 1
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/json'
      },
      success(res) {
        if (res.data.syscode == 0) {
          that.data.notice1Arr = res.data.recordList
          that.setData({
            notice1Arr: that.data.notice1Arr
          })
        }
      }
    })
    wx.request({
      url: 'https://www.xinhuo.site/api/notice/list',
      data: {
        pageNo: this.data.pageNo,
        pageSize: this.data.pageSize,
        noticeType: 2
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/json'
      },
      success(res) {
        if (res.data.syscode == 0) {
          that.data.notice2Arr = res.data.recordList
          that.setData({
            notice2Arr: that.data.notice2Arr
          })
        }
        wx.stopPullDownRefresh({
        })
      }
    })
  },
  onShow: function () {
    var that = this;
    if (app.globalData.userId) {
      this.setData({
        userId: app.globalData.userId
      });
    }
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          "wh": res.windowHeight
        })
      }
    })
  },
  moreInfo1: function () {
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../noticeList/noticeList?noticeType=1'
    })
  },
  noContent1: function () {
    wx.navigateTo({
      url: '../404/noContent?pageType=党费缴纳'
    })
  },
  noContent2: function () {
    wx.navigateTo({
      url: '../404/noContent?pageType=我的待办'
    })
  },
  moreInfo2: function () {
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../noticeList/noticeList?noticeType=2'
    })
  },
  moreInfo3: function () {
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../noticeList/noticeList?noticeType=3'
    })
  },
  toPaycost: function () {
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../paycost/paycost'
    })
  },
  toNotice: function (e) {
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../noticeDetail/noticeDetail?id=' + e.currentTarget.dataset.id
    })
  },
  toKnowledgeType: function () {
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../knowledge/knowledge?knowledgeType=-1&knowTit=知识库'
    })
  },
  toActivities: function () {
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../activities/activities'
    })
  },
  toSubject: function () {
    if (this.data.userId == null) {
      wx.navigateTo({
        url: '../binduser/binduser'
      })
    }
    wx.navigateTo({
      url: '../subject/subject'
    })
  },
})
